package custom.security.web.handle;

import custom.security.exception.FileParamsException;
import custom.security.exception.UserParamsException;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import java.util.HashMap;
import java.util.Map;

/**
 * 异常拦截器
 * Created by security on 2017/9/24.
 */


@ControllerAdvice
public class ExceptionHandle {



    @ResponseBody
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(UserParamsException.class)
    public Map<String,Object> userParamsHandle(UserParamsException ex){
        Map<String,Object> result = new HashMap();
        result.put("code","701");
        result.put("message",ex.getMessage());
        return result;
    }

    @ResponseBody
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    @ExceptionHandler(FileParamsException.class)
    public Map<String,Object> fileParamsHandle(FileParamsException ex){
        Map<String,Object> result = new HashMap();
        result.put("code","801");
        result.put("message",ex.getMessage());
        return result;
    }

}
